
#ifndef UTILS_EVENT
#define UTILS_EVENT

#include <functional>

class Event {
public:
	Event() = default;
	virtual ~Event() = default;
};

class EventDispatcher {
private:
	const Event& mEvent;
	bool mHandle;

public:
	EventDispatcher(const Event& event)
		: mEvent(event), mHandle(false) {}
	virtual ~EventDispatcher() = default;

	template<typename T>
	bool dispatch(const std::function<bool(const Event&)>& callBack) {
		if (dynamic_cast<const T*>(&mEvent) != nullptr) {
			mHandle |= callBack(mEvent);
			return true;
		}
		return false;
	}

	bool isHandled() const { return mHandle; }
};

#endif // UTILS_EVENT
